package com.bigShen.pattern.singleton.seri;

import java.io.*;

/**
 * @Auther: lei.shen
 * @Date: 2018/10/1 17:13
 * @Description:
 */
public class SerializeTest {

    public static void main(String[] args) {

        SerializeDemo singleton = SerializeDemo.getInstance();

        try {

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(singleton);
            oos.flush();
            oos.close();

            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);
            SerializeDemo serializeDemo = (SerializeDemo) ois.readObject();

            System.out.println("old " + singleton);
            System.out.println("new " + serializeDemo);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

}
